//
//  HLFeedbackVC.m
//  zhuanxian
//
//  Created by zhaoliang chen on 2017/11/17.
//  Copyright © 2017年 huiling. All rights reserved.
//

#import "HLFeedbackVC.h"
#import "UITextView+Placeholder.h"

@interface HLFeedbackVC ()

@property(nonatomic,strong)UITextView* textViewFeedback;

@end

@implementation HLFeedbackVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setNavigationTitle:@"意见反馈" Color:[UIColor whiteColor]];
    
    [self.view addSubview:self.textViewFeedback];
    [self.textViewFeedback mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(15);
        make.right.mas_equalTo(-15);
        make.height.mas_equalTo(150);
    }];
    
    UIButton* btnFeedback = [UIButton buttonWithType:UIButtonTypeCustom];
    btnFeedback.backgroundColor = MainColor;
    [btnFeedback setTitle:@"提交" forState:UIControlStateNormal];
    [btnFeedback setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btnFeedback addTarget:self action:@selector(onClickFeedback) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btnFeedback];
    [btnFeedback mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
        make.height.mas_equalTo(40);
        make.top.mas_equalTo(self.textViewFeedback.mas_bottom).offset(20);
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)onClickFeedback {
    if (self.textViewFeedback.text.length<1) {
        [SVProgressHUD showErrorWithStatus:@"请输入反馈内容!"];
        return;
    }
    [SVProgressHUD showWithStatus:@"正在提交反馈"];
    [HLWebManager feedbackAdd:self.textViewFeedback.text successBlock:^(id response) {
        if ([response[@"code"]integerValue]==1) {
            [SVProgressHUD showSuccessWithStatus:@"反馈成功"];
            [self.navigationController popViewControllerAnimated:YES];
        } else {
            [SVProgressHUD showErrorWithStatus:response[@"message"]];
        }
    } failureBlock:^(NSError *error) {
        [SVProgressHUD showErrorWithStatus:@"未知错误"];
    }];
}

- (UITextView*)textViewFeedback {
    if (!_textViewFeedback) {
        _textViewFeedback = [[UITextView alloc]init];
        _textViewFeedback.placeholder = @"请填写您的意见";
        _textViewFeedback.placeholderColor = [UIColor lightGrayColor];
        _textViewFeedback.layer.borderColor = [UIColor grayColor].CGColor;
        _textViewFeedback.layer.borderWidth = 0.6;
    }
    return _textViewFeedback;
}

@end
